package com.group.mall.controller;

import com.group.mall.domain.DTO.UserDTO;
import com.group.mall.domain.POJO.User;
import com.group.mall.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Update;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user")
@Slf4j
public class UserController {

    @Autowired
    private UserService userService;
    //新增用户
    @PostMapping("/addUser")
    public boolean addUser( UserDTO userDTO) {
        log.info("新增用户：{}", userDTO);
        Boolean result = userService.addUser(userDTO);
        return result;
    }

    @PostMapping("/update")
    void update(UserDTO userDTO){
        userService.updateUser(userDTO);
    }

    @GetMapping("/login")
    public List<User> login(String username){
        List<User> userList = userService.getUsername(username);
        return  userList;
    }


    @GetMapping("/person/{id}")
    public List<User> getUser(@PathVariable("id") Long id){
        log.info("查询{}用户信息",id);
        List<User> userList = userService.getUser(id);
        return userList;

    }
    @GetMapping("/balance")
    public List<User>Balance( Long id){
        List<User> userList = userService.getBalance(id);
        return userList;
    }

    @PostMapping("/updateRecharge")
    void updateRecharge(User user){

        userService.updateRecharge(user);
    }

}
